Imports NUnit.Framework
Imports ValidationFramework

Namespace ParameterValidationManagerExamples

    Public Class InheritedFromInterfaceHandleExample
#Region "Example"
        <TestFixture()> _
        Public Class ExampleUsage

            <Test(), ExpectedException(GetType(ArgumentException))> _
            Public Sub RunInvalidData()
                Dim person As IPerson = New Person
                person.CheckAge(7)
            End Sub

            <Test()> _
            Public Sub RunValidData()
                Dim person As IPerson = New Person
                person.CheckAge(2)
            End Sub

        End Class

        Public Class Person
            Implements IPerson

            Private Shared ReadOnly checkAgeHandle As RuntimeMethodHandle = _
                                        GetType(Person).GetMethod("CheckAge").MethodHandle

            Public Sub CheckAge(ByVal age As Int32) _
                Implements IPerson.CheckAge
                ParameterValidationManager.ThrowException(Me, _
                                                          Person.checkAgeHandle, New Object() {age})
            End Sub


        End Class

        Public Interface IPerson
            Sub CheckAge(<CompareIntRule(5, CompareOperator.LessThan)> ByVal age As Int32)
        End Interface
#End Region
    End Class
End Namespace